@extends('admin.layout')
@section('title','商品列表')
@section('body')

    <div id="search" style="height:63px;">
        <blockquote class="layui-elem-quote" style="font-size: 14px">
            <form action="" method="post" class="layui-form">
                <div class="layui-form-item">
                    <div  class="layui-inline">
                        <label class="layui-form-label">搜索</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="" name="keywords"  lay-verify="required" placeholder="请输入商品名字" autocomplete="off" class="layui-input ">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <input  type="submit" class="layui-btn layui-btn-small" value="搜索">
                        <a href="javascript:history.back()" class="layui-btn layui-btn-small" >返回</a>
                        <a href="{{url('goods/create')}}"  class="layui-btn layui-btn-small" >添加</a>
                    </div>
                </div>

            </form>
        </blockquote>
    </div>
    <table class="layui-table " >
        <colgroup>

        </colgroup>
        <thead>
        <tr>
            <th>品名</th>
            <th>封面</th>
            <th>库存</th>
            <th>价格</th>
            <th>商品编号</th>
            <th>更新时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @foreach($goods as $value)
            <tr class="@if($value->status==1) bg-success @elseif($value->status==2)bg-danger  @else bg-warning @endif">
                <td>{{$value->name}}</td>
                <td><img style="width: 80px;height: 80px" src="{{url($value->my_cover)}}" alt=""></td>
                <td>{{$value->stock}}</td>
                <td>{{$value->price}}</td>
                <td>{{$value->goods_sn}}</td>
                <td>{{$value->updated_at}}</td>
                <td >
                    @if($value->status==4)
                        <button  class="btn btn-info" @if(Session::get('admin')->type==2) disabled @endif onclick="goods_down({{$value->goods_id}})">通过</button>
                    @else
                        @if($value->status==2)
                            <button  class="btn btn-success"  onclick="goods_up({{$value->goods_id}})">上架</button>
                            <button @if($value->status==1) disabled @endif class="btn btn-primary" onclick="window.location.href='{{url('goods/edit',['goods_id'=>$value->goods_id])}}'">修改</button>
                        @elseif($value->status==1)
                            <button  class="btn btn-danger"  onclick="goods_down({{$value->goods_id}})">下架</button>
                            <button @if($value->status==1) disabled @endif class="btn btn-primary" onclick="window.location.href='{{url('goods/edit',['goods_id'=>$value->goods_id])}}'">修改</button>

                        @endif

                   @endif

                </td>
            </tr>

        @endforeach
        </tbody>
    </table>
    {!! $goods->links() !!}
@endsection
@section('js')

    <script>
        @if(Session::has('message'))
             layer.msg("{{Session::get("message")}}");
        {{Session::forget('message')}}
        @endif
        function ins() {
            layer.open({
                title:"添加参数",
                content:'<form id="ins" method="post" enctype="multipart/form-data"><input type="text" class="layui-input" name="name" placeholder="一级分类名" /><br/>icon<input name="icon"  type="file"/> <input type="hidden" name="type" value="ins"></form>',
                yes:function () {
                    $("#ins").submit();
                }
            });
        }
        function edit(name,id) {
            layer.open({
                title:"修改参数",
                content:'<form id="edit" method="post"  enctype="multipart/form-data"  ><input type="text" class="layui-input" name="name" value="'+name+'" /><input type="hidden" name="class_id" value="'+id+'"><br/>icon<input name="icon"  type="file"/><input type="hidden" name="type" value="edit"></form>',
                yes:function () {
                    $("#edit").submit();
                }
            });
        }

        function goods_up(id) {
            layer.open({
                title:"提示",
                content:'确定上架吗？！<form id="up" method="post" action="{{url('/goods/up_down')}}"><input type="hidden" name="goods_id" value="'+id+'"><input type="hidden" name="type" value=1>{{csrf_field()}}</form>',
                yes:function () {
                    $("#up").submit();
                }
            })
        }

        function goods_down(id) {
            layer.open({
                title:"提示",
                content:'确定通过吗？！<form id="down" method="post" action="{{url('/goods/up_down')}}"><input type="hidden" name="goods_id" value="'+id+'"><input type="hidden" name="type" value=2>{{csrf_field()}}</form>',
                yes:function () {
                    $("#down").submit();
                }
            })
        }

    </script>

@endsection

